package com.informet.ipd.modelo.dao;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import com.informet.ipd.modelo.vo.CrecerConDeporteVO;
import com.informet.ipd.modelo.vo.ProgEstrVO;


import com.informet.ipd.modelo.vo.UbigeoVO;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author LAPTOP01
 */
public class EventoDao extends DBase{


  Connection conn = null;

    public EventoDao() {
        super();
    }




    public void  setListAlumno(CrecerConDeporteVO bean, ResultSet rs) throws SQLException{
          
          bean.setCodAlumno(rs.getString("NUM_CODALUMCCD_PK"));
          bean.setCodCcd(Integer.parseInt(rs.getString("num_ccd_pk")));
          //bean.setNumCodNotaEvatec(rs.getString("num_codnotaevatec_pk"));
          bean.setNumCodEventoTriemsre(rs.getString("num_codeventotrimestre_pk"));
          bean.setDescEvento(rs.getString("tx_descevento"));
          

    }


public List getListEvento(String idAlumno,String idCcd,String idProfesor) throws SQLException {

        PreparedStatement pstmt = null;
        Statement stmt = null;
        ResultSet rs = null;
        ArrayList<CrecerConDeporteVO> lista = new ArrayList<CrecerConDeporteVO>(0);
        String sql = "";
        
        try {
            conn = DriverManager.getConnection(url, usuario, password);            
            stmt = conn.createStatement();
                        sql = " select "+
                              "  distinct(et.tx_descevento), "+
                              "  et.num_codeventotrimestre_pk, "+
                              "  ne.NUM_CODALUMCCD_PK, "+
                              "  ne.num_ccd_pk "+
                              "  from me_eventotrimestre et inner join me_notaevatec ne on et.num_codeventotrimestre_pk=ne.num_codeventotrimestre_pk "+
                              "                             inner join me_notaevafis nef on et.num_codeventotrimestre_pk=nef.num_codeventotrimestre_pk "+
                              "  where ne.num_codalumccd_pk="+idAlumno+
                              "        and ne.num_ccd_pk="+idCcd;
                        //"        and ne.num_ccd_pk="+idProfesor;

            rs = stmt.executeQuery(sql);
            CrecerConDeporteVO bean1 = null;
            while (rs.next()) {
                bean1 = new CrecerConDeporteVO();
                setListAlumno(bean1, rs);
                lista.add(bean1);
            }
           
        } finally {
            if (rs != null) {
                rs.close();
                rs = null;
            }
            if (stmt != null) {
                stmt.close();
                stmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }

        }
      // JOptionPane.showMessageDialog(null, lista.size());
        return lista;
    }
       
//

    public String spMan(String descEvento,String numCodNotaEvatec,String numCodEventoTriemsre,String tipoOper,String codAlumno,String codCcd) {
        String msj = "";
        //String codP=bean.getCodPrograma();
        try {

            conn = DriverManager.getConnection(url, usuario, password);
            CallableStatement cs = conn.prepareCall("{call Man_update_MeEveTriNotaEvatec(?,?,?,?,?,?)}");
            //codActividad, codAnio, titu_programa,justificacion,fechaInicio, fechaFin,monto
            cs.setString(1, descEvento);
            cs.setString(2, numCodNotaEvatec);
            cs.setString(3, numCodEventoTriemsre);
            cs.setString(4, tipoOper);
            cs.setString(5, codAlumno);
            cs.setString(6, codCcd);
            cs.execute();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString());
            msj = e.toString();
            return msj;
        }
        return msj;
    }

/*
      public String spMan(CrecerConDeporteVO bean) {
        String msj = "";
        //String codP=bean.getCodPrograma();
        try {
        	
            conn = DriverManager.getConnection(url, usuario, password);
            CallableStatement cs = conn.prepareCall("{call Man_update_MeEveTriNotaEvatec(?,?,?,?,?,?,?,?,?,?)}");
            //codActividad, codAnio, titu_programa,justificacion,fechaInicio, fechaFin,monto
            cs.setString(1, bean.getCodAlumno());
            cs.setString(2, bean.getApePaterno());
            cs.setString(3, bean.getApeMaterno());
            cs.setString(4, bean.getNombre());
            cs.setString(5, bean.getFecNacimiento());
            cs.setString(6, bean.getCondicion());
            cs.setString(7, bean.getPeso());
            cs.setString(8, bean.getTalla());
            cs.setInt(9, bean.getCodCcd());
            cs.setString(10, bean.getTipoOper());
            cs.execute();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.toString());
            msj = e.toString();
            return msj;
        }
        return msj;
    }
*/
}
